package com.tang.param_check.intecept;

import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/12/17 20:17
 * @Desc
 * @Remarks
 */
@Configuration
public class InterceptorConfigrution implements WebMvcConfigurer {

    //注意该地址为项目具体包地址
    public static final String traceExecution = "execution(* com.tang..*.controller..*.*(..))";

    /**
     * 与ParamCheckMethodInterceptor的匹配的切面配置
     * @param interceptor
     * @return
     */
    @Bean
    public DefaultPointcutAdvisor defaultPointcutAdvisor2(ParamCheckMethodInterceptor interceptor) {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(traceExecution);
        // 配置增强类advisor
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
        advisor.setPointcut(pointcut);
        advisor.setAdvice(interceptor);
        return advisor;
    }
}
